<template>
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
        <template #tableTitle>
            <a-button type="primary" @click="handleAdd" preIcon="ant-design:plus-outlined">新增</a-button>
        </template>
        <!--操作栏-->
        <template #action="{ record }">
            <TableAction divider :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)" />
        </template>
    </BasicTable>
    <Modal ref="modalRef" :isUpdate="isUpdate" :title="isUpdate ? '编辑' : '新增'" :width="896" :canFullscreen="true"
        :defaultFullscreen="true">
    </Modal>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { list } from './demandPlan.api';
import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { useListPage } from '/@/hooks/system/useListPage';
import { searchFormSchema, columns } from './demandPlan.data';
import Modal from './components/modal.vue';
import { defHttp } from '/@/utils/http/axios';

const modalRef = ref(null);
const isUpdate = ref(false);

const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
    tableProps: {
        title: '需求计划',
        api: (params) => {
            return defHttp.get({ url: '/demand/cgcjDemandPlan/list', params })
        },
        columns,
        canResize: false,
        immediate: true,
        formConfig: {
            //labelWidth: 120,
            schemas: searchFormSchema,
            autoSubmitOnEnter: true,
            showAdvancedButton: true,
            fieldMapToNumber: [
            ],
            fieldMapToTime: [
            ],
        },
        actionColumn: {
            // width: 120,
            // fixed:'right'
        },
        beforeFetch: (params) => {
            return params;
        },
    },
    // exportConfig: {
    //     name: "需求计划",
    //     url: getExportUrl,
    //     params: queryParam,
    // },
    // importConfig: {
    //     url: getImportUrl,
    //     success: handleSuccess,
    // },
});

const [registerTable, { reload }, { rowSelection, selectedRowKeys, selectedRows }] = tableContext;


// 增改相关操作
const handleAdd = () => {
    isUpdate.value = false;
    modalRef.value?.openModal();
}

// 表格相关操作
const handleEdit = (params) => {
    isUpdate.value = true;
    modalRef.value?.openModal();
    modalDetail.value = params;
}

const handleDetail = (params) => {

}

const handleDelete = (params) => {}

/**
  * 操作栏
  */
function editBtnDisabled(record: any) {
    let disabled = record.processStatus !== 'DRAFT'
    if (!disabled) {
        const userId = userStore.getUserInfo.id
        if (userId !== record.createBy) {
            disabled = true
        }
    }
    if (!disabled) {
        disabled = !editPermission.value
    }
    return disabled
}
function getTableAction(record) {
    return [
        {
            label: '编辑',
            onClick: handleEdit.bind(null, record),
            color: 'success',
            disabled: false,
            useConfirmButton: false,
            auth: 'demand:cgcj_demand_plan:edit',
        }
    ]
}


/**
 * 下拉操作栏
 */
function getDropDownAction(record) {
    return [
        {
            label: '详情',
            onClick: handleDetail.bind(null, record),
            color: 'info',
            type: 'link',
            size: 'small',
            useConfirmButton: false,
        }, {
            label: '删除',
            popConfirm: {
                title: '是否确认删除',
                confirm: handleDelete.bind(null, record),
                placement: 'topLeft'
            },
            type: 'link',
            size: 'small',
            color: 'error',
            useConfirmButton: true,
            auth: 'demand:cgcj_demand_plan:delete'
        }
    ]
}
</script>

<style scoped lang="less"></style>